package com.wzcl.app.controller.student;

import com.wzcl.app.dao.model.Orders;
import com.wzcl.app.dao.model.RefundRequest;
import com.wzcl.app.model.common.RVO;
import com.wzcl.app.service.WeChatPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author beingven
 * @Description 微信支付控制器
 * @createTime 2020年12月03日 10:19:00
 */
@RestController
@RequestMapping("/weChat")
@Api(value = "微信支付相关controller", tags = {"微信支付相关接口"})
public class WeChatPayController {
    @Resource
    private WeChatPayService weChatPayService;


    @PostMapping(value = "/native/pay")
    @ApiOperation("微信native支付接口")
    public RVO createNativePay(@RequestBody Orders orders) throws Exception {
        return weChatPayService.createNativePay(orders);
    }

    @PostMapping(value = "/h5/pay")
    @ApiOperation("微信H5支付接口")
    public RVO createWebPay(@RequestBody Orders orders) throws Exception {
        return weChatPayService.createWebPay(orders);
    }

    @PostMapping(value = "/native/notify")
    @ApiOperation("微信native支付异步通知")
    public void nativeNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
        weChatPayService.nativeCallback(request, response);
    }

    @PutMapping("/refund/apply")
    @ApiOperation("申请退款")
    public RVO applyRefund(@RequestBody RefundRequest refundRequest) throws InterruptedException {
        return weChatPayService.applyRefund(refundRequest);
    }

    @PutMapping("/refund/agree")
    @ApiOperation("退款审批")
    public RVO createRefund(@RequestBody RefundRequest refundRequest){
        return weChatPayService.createRefund(refundRequest);
    }
}